
class Solution {
public:
    int calculate(string s) {
        char sign = '+';
        int cur = 0;
        stack<int> funs;
        while (cur < s.size())
        {
            if (s[cur] == ' ') cur++;
            else {
                int num = 0;
                while (cur < s.size() && s[cur] >= '0' && s[cur] <= '9')
                {
                    if (s[cur] == ' ') cur++;
                    else num = num * 10 + (s[cur++] - '0');
                }
                if (sign == '+') funs.push(num);
                if (sign == '-') funs.push(-num);
                if (sign == '*') funs.top() *= num;
                if (sign == '/') funs.top() /= num;
                sign = s[cur++];
            }
        }
        int sum = 0;
        while (!funs.empty())
        {
            sum += funs.top();
            funs.pop();
        }
        return sum;
    }
};
class Solution {
public:
    int calculate(string s) {
        char sign = '+';
        int cur = 0;
        stack<int> funs;
        while (cur < s.size())
        {
            if (s[cur] == ' ') cur++;
            else {
                int num = 0;
                while (cur < s.size() && s[cur] >= '0' && s[cur] <= '9')
                {
                    if (s[cur] == ' ') cur++;
                    else num = num * 10 + (s[cur++] - '0');
                }
                if (sign == '+') funs.push(num);
                if (sign == '-') funs.push(-num);
                if (sign == '*') funs.top() *= num;
                if (sign == '/') funs.top() /= num;
                sign = s[cur++];
            }
        }
        int sum = 0;
        while (!funs.empty())
        {
            sum += funs.top();
            funs.pop();
        }
        return sum;
    }
};
class Solution {
public:
    string removeDuplicates(string s) {
        string sum;
        for (int cur = 0, end = -1; cur < s.size(); cur++)
            if ((!sum.empty()) && s[cur] == sum[end]) {
                sum.pop_back();
                end--;
            }
            else {
                sum += s[cur];
                end++;
            }
        return sum;
    }
};